package org.dllwh.mongodb.config;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName MongoConfig
 * @Description TODO(这里用一句话描述这个类的作用)
 * @Date 2025-05-12 17:44
 * @版本 V 1.0.1
 * @since JDK 17
 */
@Configuration
public class MongoConfig implements InitializingBean {
    @Resource
    @Lazy
    private MappingMongoConverter mappingMongoConverter;

    @Value("${spring.data.mongodb.host}")
    private String mongoDBUrl;

    @Value("${spring.data.mongodb.port}")
    private String port;

    @Value("${spring.data.mongodb.username}")
    private String mongoDBUserName;

    @Value("${spring.data.mongodb.password}")
    private String mongoDBPassword;

    @Value("${spring.data.mongodb.database}")
    private String mongoDBDatabase;

    /**
     * 去除_class列
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
    }
}
